<template>
    <div class="person-list">
        <el-table :data="items" :default-sort="{ prop: 'id', order: 'ascending' }" stripe style="width: 100%">
            <el-table-column prop="id" label="编号" sortable width="80" />
            <el-table-column label="姓名" width="120">
                <template #default="{ row }">
                    <el-tag>
                        {{ row.last_name }}{{ row.first_name }}
                    </el-tag>
                </template>
            </el-table-column>
            <el-table-column label="性别" width="60">
                <template #default="{ row }">
                        {{ row.gender === 'MALE' ? '男': '女' }}
                </template>
            </el-table-column>

            <el-table-column prop="birth_date" label="出生日期" sortable width="160" />
            <el-table-column prop="id_number" label="身份证号" width="240" />
            <el-table-column label="操作" width="180">
                <template #default="{ row }">
                    <el-button size="small" @click="emit('edit', row)">编辑</el-button>
                    <el-button size="small" type="danger" @click="emit('delete', row)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<script lang="ts" setup>
import type { Person } from "../../types/person";
defineProps<{
    items: Person[]
}>()

const emit = defineEmits<{
    (e: 'edit', person: Person): void,
    (e: 'delete', person: Person): void,
}
>()
</script>